package pl.jtb.ctl.tabory.ui.boe.ui.te;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.SectionPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

import pl.jtb.ctl.tabory.ui.boe.osgi.Activator;
import pl.jtb.ctl.tabory.ui.boe.selection.VagonSelection;
import pl.jtb.ctl.tabory.ui.boe.ui.ve.VagonMasterSectionPart;
import pl.jtb.ctl.tabory.ui.selection.ISelectionListener;
import pl.jtb.ctl.tabory.ui.selection.ISelectionProvider;

public class TripVagonSection extends SectionPart implements ISelectionProvider<VagonSelection> {

    private VagonSelection selection;
    private VagonMasterSectionPart sectionPart;

    public TripVagonSection(Composite parent, FormToolkit toolkit, int style) {
        super(parent, toolkit, style);
        initGui(toolkit);
        postInitGui();
    }

    private void initGui(FormToolkit toolkit) {
        getSection().setText(Activator.getMessage("trip.editor.vagonsection.title"));
        Composite container = toolkit.createComposite(getSection());
        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
        getSection().setClient(container);

        Set<VagonMasterSectionPart.AvailableColumnsSL> setAllColumns = new HashSet<VagonMasterSectionPart.AvailableColumnsSL>();
        setAllColumns.add(VagonMasterSectionPart.AvailableColumnsSL.COLUMN_COMPOSITION_NAME);
        setAllColumns.add(VagonMasterSectionPart.AvailableColumnsSL.COLUMN_VAGON_NAME);
        setAllColumns.add(VagonMasterSectionPart.AvailableColumnsSL.COLUMN_DISTANCE_CORRECTED);
        sectionPart = new VagonMasterSectionPart(container, toolkit, Section.NO_TITLE, Activator.getMessage("vagons.editor.table.title"), false, false, setAllColumns);
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(sectionPart.getSection());
    }

    private void postInitGui() {
        // TODO Auto-generated method stub

    }

    @Override
    public VagonSelection getSelection() {
        return selection;
    }

    @Override
    public void setSelection(VagonSelection selection) {
        this.selection = selection;
        sectionPart.setSelection(selection);
    }

    @Override
    public void addSelectionListener(ISelectionListener<VagonSelection> listner) {
    }

    @Override
    public void removeSelectionListener(ISelectionListener<VagonSelection> listner) {
    }

}
